.class public Lcom/noshufou/android/su/TagWriterActivity;
.super Landroid/app/Activity;
.source "TagWriterActivity.java"


# static fields
.field public static final EXTRA_TAG:Ljava/lang/String; = "tag"

.field private static final TAG:Ljava/lang/String; = "Su.TagWriterActivity"

.field public static final TAG_ALLOW:I = 0x1


# instance fields
.field private mNfcAdapter:Landroid/nfc/NfcAdapter;

.field private mStatusText:Landroid/widget/TextView;

.field private mTagToWrite:I


# direct methods
.method public constructor <init>()V
    .locals 1

    .prologue
    const/4 v0, 0x0

    .line 24
    invoke-direct {p0}, Landroid/app/Activity;-><init>()V

    .line 30
    iput-object v0, p0, Lcom/noshufou/android/su/TagWriterActivity;->mStatusText:Landroid/widget/TextView;

    .line 31
    iput-object v0, p0, Lcom/noshufou/android/su/TagWriterActivity;->mNfcAdapter:Landroid/nfc/NfcAdapter;

    .line 33
    const/4 v0, 0x0

    iput v0, p0, Lcom/noshufou/android/su/TagWriterActivity;->mTagToWrite:I

    .line 24
    return-void
.end method


# virtual methods
.method protected onCreate(Landroid/os/Bundle;)V
    .locals 3
    .parameter "savedInstanceState"

    .prologue
    .line 37
    invoke-super {p0, p1}, Landroid/app/Activity;->onCreate(Landroid/os/Bundle;)V

    .line 39
    invoke-static {p0}, Landroid/nfc/NfcAdapter;->getDefaultAdapter(Landroid/content/Context;)Landroid/nfc/NfcAdapter;

    move-result-object v0

    iput-object v0, p0, Lcom/noshufou/android/su/TagWriterActivity;->mNfcAdapter:Landroid/nfc/NfcAdapter;

    .line 40
    iget-object v0, p0, Lcom/noshufou/android/su/TagWriterActivity;->mNfcAdapter:Landroid/nfc/NfcAdapter;

    if-nez v0, :cond_0

    .line 41
    invoke-virtual {p0}, Lcom/noshufou/android/su/TagWriterActivity;->finish()V

    .line 44
    :cond_0
    new-instance v0, Landroid/widget/TextView;

    invoke-direct {v0, p0}, Landroid/widget/TextView;-><init>(Landroid/content/Context;)V

    iput-object v0, p0, Lcom/noshufou/android/su/TagWriterActivity;->mStatusText:Landroid/widget/TextView;

    .line 45
    iget-object v0, p0, Lcom/noshufou/android/su/TagWriterActivity;->mStatusText:Landroid/widget/TextView;

    const/16 v1, 0x11

    invoke-virtual {v0, v1}, Landroid/widget/TextView;->setGravity(I)V

    .line 46
    iget-object v0, p0, Lcom/noshufou/android/su/TagWriterActivity;->mStatusText:Landroid/widget/TextView;

    const v1, 0x7f0b00b8

    invoke-virtual {v0, v1}, Landroid/widget/TextView;->setText(I)V

    .line 48
    invoke-virtual {p0}, Lcom/noshufou/android/su/TagWriterActivity;->getIntent()Landroid/content/Intent;

    move-result-object v0

    const-string v1, "tag"

    const/4 v2, 0x0

    invoke-virtual {v0, v1, v2}, Landroid/content/Intent;->getIntExtra(Ljava/lang/String;I)I

    move-result v0

    iput v0, p0, Lcom/noshufou/android/su/TagWriterActivity;->mTagToWrite:I

    .line 49
    iget v0, p0, Lcom/noshufou/android/su/TagWriterActivity;->mTagToWrite:I

    if-nez v0, :cond_1

    .line 50
    new-instance v0, Ljava/lang/IllegalArgumentException;

    const-string v1, "You must specify a tag to write"

    invoke-direct {v0, v1}, Ljava/lang/IllegalArgumentException;-><init>(Ljava/lang/String;)V

    throw v0

    .line 53
    :cond_1
    iget-object v0, p0, Lcom/noshufou/android/su/TagWriterActivity;->mStatusText:Landroid/widget/TextView;

    invoke-virtual {p0, v0}, Lcom/noshufou/android/su/TagWriterActivity;->setContentView(Landroid/view/View;)V

    .line 54
    return-void
.end method

.method protected onNewIntent(Landroid/content/Intent;)V
    .locals 14
    .parameter "intent"

    .prologue
    const/4 v13, 0x0

    .line 86
    iget v7, p0, Lcom/noshufou/android/su/TagWriterActivity;->mTagToWrite:I

    packed-switch v7, :pswitch_data_0

    .line 139
    :cond_0
    :goto_0
    return-void

    .line 88
    :pswitch_0
    const-string v7, "android.nfc.extra.TAG"

    invoke-virtual {p1, v7}, Landroid/content/Intent;->getParcelableExtra(Ljava/lang/String;)Landroid/os/Parcelable;

    move-result-object v6

    check-cast v6, Landroid/nfc/Tag;

    .line 90
    .local v6, tagFromIntent:Landroid/nfc/Tag;
    new-instance v5, Landroid/nfc/NdefRecord;

    const/4 v7, 0x2

    .line 91
    const-string v8, "text/x-su-a"

    invoke-virtual {v8}, Ljava/lang/String;->getBytes()[B

    move-result-object v8

    .line 92
    new-array v9, v13, [B

    .line 93
    invoke-static {p0}, Landroid/preference/PreferenceManager;->getDefaultSharedPreferences(Landroid/content/Context;)Landroid/content/SharedPreferences;

    move-result-object v10

    .line 94
    const-string v11, "pin"

    const-string v12, ""

    invoke-interface {v10, v11, v12}, Landroid/content/SharedPreferences;->getString(Ljava/lang/String;Ljava/lang/String;)Ljava/lang/String;

    move-result-object v10

    invoke-virtual {v10}, Ljava/lang/String;->getBytes()[B

    move-result-object v10

    .line 90
    invoke-direct {v5, v7, v8, v9, v10}, Landroid/nfc/NdefRecord;-><init>(S[B[B[B)V

    .line 95
    .local v5, record:Landroid/nfc/NdefRecord;
    new-instance v3, Landroid/nfc/NdefMessage;

    const/4 v7, 0x1

    new-array v7, v7, [Landroid/nfc/NdefRecord;

    aput-object v5, v7, v13

    invoke-direct {v3, v7}, Landroid/nfc/NdefMessage;-><init>([Landroid/nfc/NdefRecord;)V

    .line 97
    .local v3, message:Landroid/nfc/NdefMessage;
    invoke-static {v6}, Landroid/nfc/tech/Ndef;->get(Landroid/nfc/Tag;)Landroid/nfc/tech/Ndef;

    move-result-object v4

    .line 98
    .local v4, ndef:Landroid/nfc/tech/Ndef;
    if-eqz v4, :cond_3

    .line 99
    invoke-virtual {v4}, Landroid/nfc/tech/Ndef;->isWritable()Z

    move-result v7

    if-nez v7, :cond_1

    .line 100
    const-string v7, "Tag not writeable"

    invoke-static {p0, v7, v13}, Landroid/widget/Toast;->makeText(Landroid/content/Context;Ljava/lang/CharSequence;I)Landroid/widget/Toast;

    move-result-object v7

    invoke-virtual {v7}, Landroid/widget/Toast;->show()V

    goto :goto_0

    .line 104
    :cond_1
    invoke-virtual {v4}, Landroid/nfc/tech/Ndef;->getMaxSize()I

    move-result v2

    .line 106
    .local v2, maxSize:I
    invoke-virtual {v3}, Landroid/nfc/NdefMessage;->toByteArray()[B

    move-result-object v7

    array-length v7, v7

    if-ge v2, v7, :cond_2

    .line 107
    const-string v7, "Tag not big enough"

    invoke-static {p0, v7, v13}, Landroid/widget/Toast;->makeText(Landroid/content/Context;Ljava/lang/CharSequence;I)Landroid/widget/Toast;

    move-result-object v7

    invoke-virtual {v7}, Landroid/widget/Toast;->show()V

    goto :goto_0

    .line 111
    :cond_2
    :try_start_0
    invoke-virtual {v4}, Landroid/nfc/tech/Ndef;->connect()V

    .line 112
    invoke-virtual {v4, v3}, Landroid/nfc/tech/Ndef;->writeNdefMessage(Landroid/nfc/NdefMessage;)V

    .line 113
    invoke-virtual {p0}, Lcom/noshufou/android/su/TagWriterActivity;->finish()V
    :try_end_0
    .catch Ljava/io/IOException; {:try_start_0 .. :try_end_0} :catch_0
    .catch Landroid/nfc/FormatException; {:try_start_0 .. :try_end_0} :catch_1

    goto :goto_0

    .line 114
    :catch_0
    move-exception v0

    .line 115
    .local v0, e:Ljava/io/IOException;
    const-string v7, "Su.TagWriterActivity"

    const-string v8, "IOException"

    invoke-static {v7, v8, v0}, Landroid/util/Log;->e(Ljava/lang/String;Ljava/lang/String;Ljava/lang/Throwable;)I

    goto :goto_0

    .line 117
    .end local v0           #e:Ljava/io/IOException;
    :catch_1
    move-exception v0

    .line 118
    .local v0, e:Landroid/nfc/FormatException;
    const-string v7, "Su.TagWriterActivity"

    const-string v8, "FormatException"

    invoke-static {v7, v8, v0}, Landroid/util/Log;->e(Ljava/lang/String;Ljava/lang/String;Ljava/lang/Throwable;)I

    goto :goto_0

    .line 122
    .end local v0           #e:Landroid/nfc/FormatException;
    .end local v2           #maxSize:I
    :cond_3
    invoke-static {v6}, Landroid/nfc/tech/NdefFormatable;->get(Landroid/nfc/Tag;)Landroid/nfc/tech/NdefFormatable;

    move-result-object v1

    .line 123
    .local v1, format:Landroid/nfc/tech/NdefFormatable;
    if-eqz v1, :cond_0

    .line 125
    :try_start_1
    invoke-virtual {v1}, Landroid/nfc/tech/NdefFormatable;->connect()V

    .line 126
    invoke-virtual {v1, v3}, Landroid/nfc/tech/NdefFormatable;->format(Landroid/nfc/NdefMessage;)V

    .line 127
    invoke-virtual {p0}, Lcom/noshufou/android/su/TagWriterActivity;->finish()V
    :try_end_1
    .catch Ljava/io/IOException; {:try_start_1 .. :try_end_1} :catch_2
    .catch Landroid/nfc/FormatException; {:try_start_1 .. :try_end_1} :catch_3

    goto/16 :goto_0

    .line 128
    :catch_2
    move-exception v0

    .line 129
    .local v0, e:Ljava/io/IOException;
    const-string v7, "Su.TagWriterActivity"

    const-string v8, "IOException"

    invoke-static {v7, v8, v0}, Landroid/util/Log;->e(Ljava/lang/String;Ljava/lang/String;Ljava/lang/Throwable;)I

    goto/16 :goto_0

    .line 131
    .end local v0           #e:Ljava/io/IOException;
    :catch_3
    move-exception v0

    .line 132
    .local v0, e:Landroid/nfc/FormatException;
    const-string v7, "Su.TagWriterActivity"

    const-string v8, "FormatException"

    invoke-static {v7, v8, v0}, Landroid/util/Log;->e(Ljava/lang/String;Ljava/lang/String;Ljava/lang/Throwable;)I

    goto/16 :goto_0

    .line 86
    nop

    :pswitch_data_0
    .packed-switch 0x1
        :pswitch_0
    .end packed-switch
.end method

.method protected onPause()V
    .locals 1

    .prologue
    .line 78
    invoke-super {p0}, Landroid/app/Activity;->onPause()V

    .line 79
    iget-object v0, p0, Lcom/noshufou/android/su/TagWriterActivity;->mNfcAdapter:Landroid/nfc/NfcAdapter;

    if-eqz v0, :cond_0

    .line 80
    iget-object v0, p0, Lcom/noshufou/android/su/TagWriterActivity;->mNfcAdapter:Landroid/nfc/NfcAdapter;

    invoke-virtual {v0, p0}, Landroid/nfc/NfcAdapter;->disableForegroundDispatch(Landroid/app/Activity;)V

    .line 82
    :cond_0
    return-void
.end method

.method protected onResume()V
    .locals 9

    .prologue
    const/4 v8, 0x1

    const/4 v7, 0x0

    .line 58
    invoke-super {p0}, Landroid/app/Activity;->onResume()V

    .line 60
    new-instance v5, Landroid/content/Intent;

    invoke-virtual {p0}, Ljava/lang/Object;->getClass()Ljava/lang/Class;

    move-result-object v6

    invoke-direct {v5, p0, v6}, Landroid/content/Intent;-><init>(Landroid/content/Context;Ljava/lang/Class;)V

    const/high16 v6, 0x2000

    invoke-virtual {v5, v6}, Landroid/content/Intent;->addFlags(I)Landroid/content/Intent;

    move-result-object v5

    .line 59
    invoke-static {p0, v7, v5, v7}, Landroid/app/PendingIntent;->getActivity(Landroid/content/Context;ILandroid/content/Intent;I)Landroid/app/PendingIntent;

    move-result-object v3

    .line 61
    .local v3, pendingIntent:Landroid/app/PendingIntent;
    new-instance v2, Landroid/content/IntentFilter;

    const-string v5, "android.nfc.action.NDEF_DISCOVERED"

    invoke-direct {v2, v5}, Landroid/content/IntentFilter;-><init>(Ljava/lang/String;)V

    .line 63
    .local v2, ndef:Landroid/content/IntentFilter;
    :try_start_0
    const-string v5, "*/*"

    invoke-virtual {v2, v5}, Landroid/content/IntentFilter;->addDataType(Ljava/lang/String;)V
    :try_end_0
    .catch Landroid/content/IntentFilter$MalformedMimeTypeException; {:try_start_0 .. :try_end_0} :catch_0

    .line 68
    new-array v1, v8, [Landroid/content/IntentFilter;

    aput-object v2, v1, v7

    .line 69
    .local v1, filters:[Landroid/content/IntentFilter;
    const/4 v5, 0x2

    new-array v4, v5, [[Ljava/lang/String;

    .line 70
    new-array v5, v8, [Ljava/lang/String;

    const-class v6, Landroid/nfc/tech/Ndef;

    invoke-virtual {v6}, Ljava/lang/Class;->getName()Ljava/lang/String;

    move-result-object v6

    aput-object v6, v5, v7

    aput-object v5, v4, v7

    .line 71
    new-array v5, v8, [Ljava/lang/String;

    const-class v6, Landroid/nfc/tech/NdefFormatable;

    invoke-virtual {v6}, Ljava/lang/Class;->getName()Ljava/lang/String;

    move-result-object v6

    aput-object v6, v5, v7

    aput-object v5, v4, v8

    .line 73
    .local v4, techLists:[[Ljava/lang/String;
    iget-object v5, p0, Lcom/noshufou/android/su/TagWriterActivity;->mNfcAdapter:Landroid/nfc/NfcAdapter;

    invoke-virtual {v5, p0, v3, v1, v4}, Landroid/nfc/NfcAdapter;->enableForegroundDispatch(Landroid/app/Activity;Landroid/app/PendingIntent;[Landroid/content/IntentFilter;[[Ljava/lang/String;)V

    .line 74
    .end local v1           #filters:[Landroid/content/IntentFilter;
    .end local v4           #techLists:[[Ljava/lang/String;
    :goto_0
    return-void

    .line 64
    :catch_0
    move-exception v0

    .line 65
    .local v0, e:Landroid/content/IntentFilter$MalformedMimeTypeException;
    const-string v5, "Su.TagWriterActivity"

    const-string v6, "Bad MIME type declared"

    invoke-static {v5, v6, v0}, Landroid/util/Log;->e(Ljava/lang/String;Ljava/lang/String;Ljava/lang/Throwable;)I

    goto :goto_0
.end method
